package cn.biplam.setup.code;

import cn.biplam.back.jda.Jda;
import cn.biplam.common.bean.sqlengine.Sql;
import cn.biplam.common.client.DbResource;
import cn.biplam.common.tools.DEBUG;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.sqlresult.SqlResult;

/**
 * 数据操作类,用于执行SQL
 * @author XiaoRuxing Sep 29, 20099:17:27 AM
 * @version 1.0
 */
public class Data {

	/**
	 * 执行sql
	 * @throws ErrorMessage 
	 */
	protected boolean executeDMLSqlBatch(String[] sql) {
		try {
			DbResource mDbResource = new DbResource(DbResource.RT);
			Jda mJda = new Jda(mDbResource);
			return mJda.executeDMLBatch(sql);
		} catch (ErrorMessage e) {
			DEBUG.println("Sql执行错误:"+sql);
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 * 执行sql
	 * @throws ErrorMessage 
	 */
	protected boolean executeDMLSql(String sql) {
		try {
			DbResource mDbResource = new DbResource(DbResource.RT);
			Jda mJda = new Jda(mDbResource);
			return mJda.executeDDL(new Sql(sql));
		} catch (ErrorMessage e) {
			DEBUG.println("Sql执行错误:"+sql);
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 执行sql
	 * @throws ErrorMessage 
	 */
	protected SqlResult executeSelectSql(String sql) {
		SqlResult result = null;
		try {
			DbResource mDbResource = new DbResource(DbResource.RT);
			Jda mJda = new Jda(mDbResource);
			result =  mJda.executeSelect(new Sql(sql));
		} catch (ErrorMessage e) {
			DEBUG.println("Sql执行错误:"+sql);
			e.printStackTrace();
		}
		return result;
	}
}
